package lesson15;


public class Car {
	String model;
	int maxSpeed;
	int currentSpeed;
	String color;
	byte currentGear;
	Person owner;
	double price;
	boolean isSportsCar;
	String regNumber;
	
	
	Car(String model){
		this.model = model;
	}
	
	boolean isMoreExpensive(Car car)    {	return this.price > car.price;  	} 
	
	Car(String model, boolean isSportsCar,String color,double price, int maxSpeed){
		this(model);		
		
		this.isSportsCar = isSportsCar;
		
		if(this.isSportsCar && maxSpeed>200){
			this.maxSpeed = maxSpeed;
		}     
		this.color = color;
		this.price = price;
		
	}
	
	void accelerate(int speed){
		if(currentSpeed + speed > maxSpeed){
			currentSpeed = maxSpeed;
		}else currentSpeed += speed;
		if(speed > 30){
			changeGearUp(1);
		}
		
	}
	
	void changeGearDown(int gear){
		if(currentGear - gear < 1){
			currentGear = 1;
		}else currentGear--;
	}
	void changeGearUp(int gear){
		if(currentGear + gear > 6){
			currentGear = 6;
		}else currentGear++;
	}
	void changeColor(String newColor) {color = newColor;}
	void changeGear(byte newGear){
		if(newGear<1){
			currentGear=1;
		}else if(newGear>6){
			currentGear = 6;
		}else 
			currentGear=newGear;
	}

	double calculateCarPriceForScrap(double metalPrice){	
		double coef = 0.2;
		if(this.color.equalsIgnoreCase("Black"))
			coef+=0.05;
		if(this.isSportsCar)
			coef+=0.05;
		metalPrice *=coef;
		return metalPrice ;
	}
}
